<?php
	// Prototype Implementasi Multi Bahasa
	
	// CEK Akses Data
	if ((!defined("ADMIN-AREA")) || (!in_array(SHOWVIEW,$_SESSION['access']))) {
		die("No data");
	} else {
		unset($_SESSION['access']);
	}
	
	//Untuk menampilkan tombol aksi data (Lihat dan Tambah) 
	include_once "modul/funct_stat.php";

	//Untuk fungsi berikut sudah di define.
	//ACT = $_GET['act'];
	//SHOW = $_GET['show'];
	//SHOWVIEW = $_GET['showview'];
	//Penting :
	//Deklarasikan variable yang akan digunakan pada folder langs di setiap modul
	//Lihat daftar variabel yang telah di deklarasikan pada folder langs untuk digunakan pada modul ini

	if (ACT=="edit") {
		$arr1 = array("<fieldset","<input","</fieldset","<text","</text","<legend","</legend","<label","</label","<form","</form","<script","<?php","<%","<!--","<link","<style","</scr","</link","</code","<pre","/pre>");
		$arr2 = array("&lt;fieldset","&lt;input","&lt;/fieldset","&lt;text","&lt;/text","&lt;legend","&lt;/legend","&lt;label","&lt;/label","&lt;form","&lt;/form","&lt;script","&lt;?php","&lt;%","&lt;!--","&lt;link","&lt;a","&lt;/scr","&lt;link","&lt;code","<div align=\"center\"><pre style=\"position:relative; width:450px; overflow:auto; text-align:left;\"","/pre></div>");
		$kode = (int) $_GET['kode'];
		$sql1 = "SELECT * FROM tbl_content WHERE idx='".$kode."' LIMIT 1";
		$qry1 = mysql_query($sql1);
		while ($row1 = mysql_fetch_object($qry1)) {
			$judul = $row1->judul;
			$isi = str_replace($arr1,$arr2,$row1->isi);
			$header_c = $row1->header_c;
			$tipe = explode("-",$row1->tipe);
			$tipe = $tipe[0];
			if (($row1->status)==1) {
				$pubx = "checked";
			};
		};
		
		$tagval = $queryData->selek1('x_fieldvalue',"id_user='".$kode."' AND tipe='tag'")->fieldvalue;
		$thumbnail_name = $queryData->selek1('x_fieldvalue',"id_user='".$kode."' AND tipe='post'")->fieldvalue;
		
		$form_stat = 'edit';
	} else {
		$header_cX = $NEWS_HEADER_TIPS;
		$form_stat = 'input';
	}
	if ((ACT=="tambah") || (ACT=="edit")) {
		//Implementasi penggunaan validasi form menggunakan Javascript (lihat change_log.txt)
?>
<form name="form1" id="form1" method="post" action="<?php echo $path; ?>ver_berita.php?show=<?php echo SHOW; ?>&amp;showview=<?php echo SHOWVIEW; ?>" onsubmit="MM_validateForm('<?php echo $NEWS_TITLE; ?>','','R','<?php echo $NEWS_HEADER; ?>','','R','isi','','R');return document.MM_returnValue">
  <table width="75%" border="0" align="center" cellpadding="4" cellspacing="1" class="content-arial">
    <tr valign="top"> 
      <td width="21%" valign="middle" nowrap> <div align="right"><?php echo $NEWS_TITLE; ?>*</div></td>
      <td width="5%" valign="middle"> <div align="center">:</div></td>
      <td width="74%"> <div align="left"> 
          <input name="judul" id="<?php echo $NEWS_TITLE; ?>" type="text" size="50" value="<?php echo $judul; ?>" class="input-title" />
        </div></td>
    </tr>
    <tr>
			<td valign="middle" nowrap="nowrap"><div align="right"><?php echo $NEWS_TYPE; ?>*</div></td>
    <td><div align="center">:</div></td>
    	<td><select name="type" id="type" style="width:100px">
    	  <?php
						$sqlQ = "SELECT * FROM tbl_kategori WHERE tipe='beritaartikel'";
						$qryQ = mysql_query($sqlQ);
						while ($rowQ = mysql_fetch_object($qryQ)) {
							echo '<option value="'.$rowQ->kategori.'"';
							if ($rowQ->kategori==$tipe)
								echo ' selected';
							echo '>'.$rowQ->kategori.'</option>';
						}
					?>
  	  </select> <?php echo $queryData->tagCloud('create',$tagval,'tag','TAGNAME',$kode,'tagCloud','',''); ?></td>
   	</tr>
    <tr valign="top"> 
      <td nowrap> <div align="right"><?php echo $NEWS_HEADER; ?>*</div></td>
      <td> <div align="center">:</div></td>
      <td><div align="left" class="disable"><span><?php echo $header_cX; ?></span></div>
      <div align="left"> 
          <textarea name="header_c" cols="65" rows="5" wrap="physical" id="<?php echo $NEWS_HEADER; ?>"><?php echo $header_c; ?></textarea>
      </div></td>
    </tr>
    <tr valign="top"> 
      <td nowrap> <div align="right"><?php echo $NEWS_CONTENT; ?>*<br />
      <a class="toggleEditor" href="javascript:toggleEditor('isi');">Toggle Editor</a></div></td>
      <td> <div align="center">:</div></td>
      <td> <div align="left"><textarea name="isi" cols="65" id="isi" rows="20"><?php echo htmlspecialchars($isi); ?></textarea>
        </div></td>
    </tr>
<?php
	if (isset($_SESSION['isroot'])) {
?>
    <tr valign="top"> 
      <td><div align="right"><?php echo $NEWS_PUBLISH; ?></div></td>
      <td><div align="center">:</div></td>
      <td><div align="left"> 
          <input name="publish" type="checkbox" id="publish" value="ya" <?php echo $pubx; ?> /> <?php echo $DEV_YES; ?>
        </div></td>
    </tr>
<?php
	}
?>
    <tr valign="top">
      <td valign="top"><div align="right"><?php echo $NEWS_IMAGE_THUMBNAILS; ?></div></td>
      <td valign="top"><div align="center">:</div></td>
      <td><div align="left"><input name="upbanner" type="text" id="<?php echo $NEWS_IMAGE_THUMBNAILS; ?>" readonly="readonly" onclick="return setFile('<?php echo $NEWS_IMAGE_THUMBNAILS; ?>');" value="<?php echo $thumbnail_name; ?>">&nbsp;<button name="browse" onclick="return setFile('<?php echo $NEWS_IMAGE_THUMBNAILS; ?>');">Browse</button><br />
      <?php
		if (file_exists($thum)) {
			echo $NEWS_TIPS_CURR_FILE.'<br />';
			echo "<a href=\"".$thum."\"><img src=\"images/download.gif\" /></a>";
		};
	?><br /><?php echo $NEWS_TIPS_FILE; ?></div></td>
    </tr>
    <tr valign="top"> 
      <td> <div align="right"></div></td>
      <td> <div align="center"></div></td>
      <td> <div align="left">
        <input type="submit" name="submit" id="submit" value="<?php echo $DEV_CTRL_SUBMIT; ?>" />
          <input type="reset" name="Reset" value="<?php echo $DEV_CTRL_RESET; ?>" />
<input name="act_ver" type="hidden" id="act_ver" value="<?php echo strtolower($form_stat); ?>" />
          <input name="kode" type="hidden" id="kode" value="<?php echo (int) $_GET['kode']; ?>" />
      </div></td>
    </tr>
  </table>
</form>
<?php
	} else {
		//Menampilkan Form pencarian Data
		echo $queryData->cari_form($NEWS_SEARCH);
		//Query form untuk filter pencarian data (hanya 2 pilihan field yang dapat dicari)
		//judul dan isi adalah nama field pada database
		$caridata = $queryData->cari_padaku("judul","isi");
		//Implementasikan variable caridata pada Query
		if (isset($_SESSION['isroot'])) {
			$sql1 = "SELECT * FROM tbl_content WHERE (tipe='berita' OR tipe='artikel') ".$caridata." ORDER BY tanggal DESC LIMIT ".$limitdown.",10";	
		} else {
			$sql1 = "SELECT * FROM tbl_content WHERE (tipe='berita' OR tipe='artikel') ".$caridata." AND author='".$_SESSION['author']."' ORDER BY tanggal DESC LIMIT ".$limitdown.",10";	
		}
?>
<table align="center" cellpadding="4" cellspacing="2" class="imagesSUB">
	<tr>
		<th width="250" height="30" class="imagesSUB"><div align="center"><?php echo $NEWS_TITLE; ?></div></th>
		<th width="124" class="imagesSUB"><div align="center"><?php echo $NEWS_TYPE; ?></div></th>
		<th width="50" class="imagesSUB"><div align="center"><?php echo $NEWS_PUBLISH; ?></div></th>
		<th width="75" class="imagesSUB"><div align="center"><?php echo $NEWS_AUTHOR; ?></div></th>
		<th width="100" class="imagesSUB"> <div align="center"><?php echo $NEWS_DATE; ?></div></th>
		<th width="50" class="imagesSUB"><div align="center"><?php echo $DEV_ACTION; ?></div></th>
	</tr>
	<?php
		$qry1 = mysql_query($sql1);
		$numrow = mysql_num_rows($qry1);
		$num = 1;
		$x = 1;
		if ($numrow==0) {
			echo '<tr><th colspan="6">'.$DEV_NO_DATA.'</th></tr>';
		} else {
			while ($row1 = mysql_fetch_object($qry1)) {
				$data = $x % 2;
				if ($data==0) {
					$dataX = "ganjil";
				} else {
					$dataX = "genap";
				} 
?>
	<tr valign="top" class="<?php echo $dataX; ?>" onmouseover="setBG('bg<?php echo $x; ?>','#FFFFDD')" onmouseout="setBG('bg<?php echo $x; ?>','')" id="bg<?php echo $x; ?>">
		<td><div align="left"><?php echo $row1->judul; ?></div></td>
		<td><div align="center"><?php echo $row1->tipe; ?></div></td>
		<td><div align="center"><?php (($row1->status)==1) ? print "<img src=\"images/ico_check.gif\" width=\"16\" height=\"16\"></div></td>" : print "<img src=\"images/ico_delete.gif\" width=\"16\" height=\"16\"></div></td>"; ?></div></td>
		<td nowrap="nowrap"><div align="left"><?php echo $queryData->cekUser($row1->author); ?></div></td>
		<td nowrap="nowrap"><div align="left"><?php echo $queryData->tanggalan($row1->tanggal,true);?></div></td>
		<?php 
		//Menampilkan tombol aksi dalam tabel (lihat change_log.txt)
		echo $queryData->ctrl_data('','index.php?show='.SHOW.'&showview='.SHOWVIEW.'&act=edit&kode='.$row1->idx,$path.'ver_berita.php?show='.SHOW.'&amp;showview='.SHOWVIEW.'&amp;kode='.$row1->idx.'&amp;act_ver=Hapus'); ?>
	</tr>
		<?php 
				$num++;
				$x++;
			}
		}
?>
</table>
<div align="center"><?php 
//Untuk menampilkan next previous
echo $queryData->next_prev($num,$pages_syarat,$limitdown); ?></div>
<?php
	}
?>